#include "loglog.h"

char logBuff[BUFF_SIZE];

void logInit(void)
{
	memset(logBuff, 0, BUFF_SIZE);
}

void logInfo(char *fmt, ...)
{
	va_list args;
	if (fmt == 0 || strlen(fmt) == 0)
	{
		return;
	}
	if (LOG_LEVEL >= LOG_LEVEL_INFO)
	{
		strcpy(logBuff, "[INFO]: ");
		va_start(args, fmt);
		vsnprintf(logBuff + strlen(logBuff), BUFF_SIZE - 1 - strlen(logBuff), fmt, args);
		strcat(logBuff, "\n");
		va_end(args);
		printf("%s", logBuff);
	}
}

void logWarn(char *fmt, ...)
{
	va_list args;
	if (fmt == 0 || strlen(fmt) == 0)
	{
		return;
	}
	if (LOG_LEVEL >= LOG_LEVEL_WARN)
	{
		strcpy(logBuff, "[WARNING]: ");
		va_start(args, fmt);
		vsnprintf(logBuff + strlen(logBuff), BUFF_SIZE - 1 - strlen(logBuff), fmt, args);
		strcat(logBuff, "\n");
		va_end(args);
		printf("%s", logBuff);
	}
}

void logError(char *fmt, ...)
{
	va_list args;
	if (fmt == 0 || strlen(fmt) == 0)
	{
		return;
	}
	if (LOG_LEVEL >= LOG_LEVEL_ERRO)
	{
		strcpy(logBuff, "[ERROR]: ");
		va_start(args, fmt);
		vsnprintf(logBuff + strlen(logBuff), BUFF_SIZE - 1 - strlen(logBuff), fmt, args);
		strcat(logBuff, "\n");
		va_end(args);
		printf("%s", logBuff);
	}
}
